package graduate.cslg.com.universityshopping.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import graduate.cslg.com.universityshopping.R;
import graduate.cslg.com.universityshopping.entity.CardCostBean;

public class CostInfoAdapter extends RecyclerView.Adapter<CostInfoAdapter.ViewHolder> {

    private Context mContext;
    private List<CardCostBean> mCostBeans;

    public class ViewHolder extends RecyclerView.ViewHolder {

        private TextView costType;
        private TextView costPlace;
        private TextView costTime;
        private TextView costMoney;

        public ViewHolder(View itemView) {
            super(itemView);
            costType = itemView.findViewById(R.id.cost_type);
            costPlace = itemView.findViewById(R.id.cost_place);
            costTime = itemView.findViewById(R.id.cost_time);
            costMoney = itemView.findViewById(R.id.cost_money);
        }
    }

    public CostInfoAdapter(List<CardCostBean> costBeans) {
        mCostBeans = costBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_cost_info, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CardCostBean costBean = mCostBeans.get(position);
        holder.costMoney.setText("-" + String.valueOf(costBean.getCost_money()));
        holder.costTime.setText(costBean.getCost_time());
        holder.costPlace.setText(costBean.getCost_station_name());
        holder.costType.setText(costBean.getCost_detail());
    }

    @Override
    public int getItemCount() {
        return mCostBeans.size();
    }
}
